<?php
	include_once "dataservice.php";
	
	class menu_db
	{
		public function Them($MaMenu, $TenMenu, $Link, $Current, $Index)
		{
			$sql = "INSERT INTO `tbl_menu`(`MaMenu`, `TenMenu`, `Link`, `Current`, `Index`) 
					VALUES ('$MaMenu', '$TenMenu', '$TenMenu', '$Current', '$Index')";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaMenu, $TenMenu, $Link, $Current, $Index)
		{
			$sql = "UPDATE `tbl_menu` 
					SET `TenMenu`='$TenMenu',`Link`='$TenMenu', `Current`=('$Current'), `Index`='$Index' 
					WHERE `MaMenu`='$MaMenu'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function CapNhatPIN($MaMenu, $PIN)
		{
			$sql = "UPDATE 	`tbl_menu` 
					SET 	`PIN`='$PIN'
					WHERE 	`MaMenu`='$MaMenu'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function CapNhatIndex($MaMenu, $Index)
		{
			$sql = "UPDATE 	`tbl_menu` 
					SET 	`Index`='$Index' 
					WHERE 	`MaMenu`='$MaMenu'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function CapNhatTrangThai($MaMenu, $TrangThai)
		{
			$sql = "UPDATE 	`tbl_menu` 
					SET 	`TrangThai`='$TrangThai'
					WHERE 	`MaMenu`='$MaMenu'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function ChonCurrent($MaMenu, $Current)
		{
			$sql = "UPDATE `tbl_menu` 
					SET `Current`='$Current' 
					WHERE `MaMenu`='$MaMenu'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaMenu)
		{
			$sql = "DELETE FROM `tbl_menu` WHERE MaMenu = '$MaMenu'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaMenu, $TrangThai)
		{
			$sql = "SELECT * FROM `tbl_menu` WHERE 1";
			
			if($MaMenu != 0)
				$sql .= " AND `MaMenu` = $MaMenu";
			if($TrangThai != -1)
				$sql .= " AND `TrangThai` = $TrangThai";
			
			$sql .= " ORDER BY `Index` ASC";
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}
		
		public function MaxIndex()
		{
			$sql = "SELECT MAX(`Index`) FROM `tbl_menu`";
			
			$service = new dataservice();
			return $service->ExecuteScalar($sql);
		}
	}
?>